home *** CD-ROM | disk | FTP | other *** search
- ;Palette Remapping example
- ;Fast Ram bitmap testing code added APR 24, 1998
- ;by Curt Esser camge@ix.netcom.com
- ;speed improvements thanks to Xavier Nuel ( BadDolls )
- ;use any part of this in any way you like
-
- ;NOTE : NEEDS BDGFX library! (C) BadDolls Production
- ;You can find this small library in Aminet/dev/basic
- ;or at http://www.a2points.com/homepage/3698138
-
- ;NOTE : The remapping part of the code only works on AGA systems!
-
- WBStartup ;just in case!
- WBenchToFront_ ;make sure it shows
- WbToScreen 0 ;grab the wb screen
- ScreensBitMap 0,0
- NoCli ;don't need that!
-
-
- ;==== Get info about current Workbench Screen and grab it's palette =======
-
- Dim col.w(255) ;for storing colour matches
- maxw=WBWidth ;these are used to set our window
- maxh=WBHeight ;size later
- wd.w=WBDepth ;number of bitplanes of WB
- WBcolors.w=2^wd ;convert this to number of colours
- aga.b=CheckAGA ;see if system is AGA
- MaxLen fi$=200 ;these are needed for the
- MaxLen pa$=200 ;ASL requestor
- accuracy.w=0 ;accuracy of remapping - 0-255
- ;higher = faster but less accurate
-
- ;------------- Store the WB palette as palette #0 -------------------------
-
- InitPalette 0,WBcolors ;set up palette 0 to WB depth
-
- For i=0 To WBcolors-1
- AGAPalRGB 0,i,AGARed(i),AGAGreen(i),AGABlue(i)
- Next
-
- ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- Repeat ;TEST LOOP STARTS HERE!
-
- Window 0,0,0,1,1,$1000,"",1,0 ;needed for requestors
- CatchDosErrs ;show requestors here!
-
- picpath$=ASLFileRequest$("Select IFF picture",pa$,fi$)
- If picpath$="" Then End ;exit program when "cancel" is selected
-
- error$=""
- If ReadFile(0,picpath$) ;make sure it is a valid iff picture file!
- FileInput 0
- header$ = Inkey$(2000) ;Read 2000 bytes of the header
- CloseFile 0
- WindowInput 0
-
- ;IFF picture header should read: FORM....ILBM
-
- If Left$(header$,4)<> "FORM" OR Mid$(header$,9,4) <> "ILBM"
- If Left$(header$,3)="GIF" Then error$="GIF "
- If Mid$(header$,7,4)="JFIF" Then error$="JPEG"
- If Mid$(header$,9,4)="ANIM" Then error$="ANIM"
- If error$="" Then error$="ERROR"
-
- Else ;Valid IFF header found!
- ham=False ;we can't remap HAM pic, so check
- x.w=Instr(header$,"CAMG")
- If x<>0
- a$=Left$(Right$(Hex$(Peek.l(&header$+x+7) AND $88A4),3),1)
- If a$="8" Then error$="HAM "
- EndIf
- x=Instr(header$,"CMAP") ;24 bit pics will crash!
- If x=0 Then error$="True Color (24 bit)"
- EndIf
- Else ;couldn't even find the file!
- error$="NF"
- EndIf
-
- If error$="" ;Valid iff picture selected!
-
- ; ------ check for enough chip memory for the conversion -----------------
-
- ILBMInfo picpath$ ;read the pictures size information
-
- sd.w=ILBMDepth
- sh.w=ILBMHeight
- sw.w=ILBMWidth
- planemem.l=sh*sw/8 ;bytes needed for 1 bitplane of this pic
- planes.b=wd ;calculate total bitplanes needed
- planes+sd
- chipstart.l=AvailMem_(#MEMF_CHIP)
- mem.l=planes*planemem+20000 ;total chipmem required & some padding
- memfast.l=AvailMem_(#MEMF_FAST|#MEMF_LARGEST)
- If mem>memfast
- error$="MEM"
- EndIf
- EndIf
-
- If error$="" ;get ready to process picture
- b1size.l=sw*sh*wd/8 ;memory needed for "input" bitmap
- b2size.l=sw*sh*sd/8 ;memory needed for "output" bitmap
- b1.l=AllocMem_(b1size,#MEMF_FAST)
- *b1p =b1
- CludgeBitMap 1,sw,sh,wd,b1
- b2.l=AllocMem_(b2size,#MEMF_FAST)
- *b2p=b2
- CludgeBitMap 2,sw,sh,sd,b2
-
- LoadBitMap 2,picpath$,1 ;now load the pic & it's palette
- shapecolors.w=2^sd ;convert depth to number of colours
- chipused.l = chipstart-AvailMem_(#MEMF_CHIP)
- rq$=Str$(sw)+"x"+Str$(sh)+"x"+Str$(shapecolors)+"|Picture loaded"
- rq$=rq$+"|"+Str$(chipused)+" bytes of chip ram used"
- Request "",rq$,"OK"
- Format""
- i$="Remap "+Str$(sw)+" x "+Str$(sh)+" "
- i$=i$+Str$(shapecolors)+" colour picture "
-
- ;-------------Remap the picture's palette to WB palette--------------------
-
- PaletteInfo 1
- For i = 0 To shapecolors-1 ;remap the shape to wb screen
- col(i)=FindColor(0,AGAPalRed(i),AGAPalGreen(i),AGAPalBlue(i),accuracy)
- Next
-
- a=PICreateRequest(i$,0,sw,1)
-
-
- For x=0 To sw-1
- a=PIUpdateRequest(x)
- For y=0 To sh-1
- Use BitMap 2
- match=Point(x,y)
- Use BitMap 1
- Plot x,y,col(match)
- Next y
- Next x
-
- ;Free BitMap 2
- success=FreeMem_(*b2p,b2size)
- VWait
- PIEndRequest
-
- ;------------Open a window and put the picture on it-----------------------
-
- winwid=sw
- If winwid>maxw Then winwid=maxw
- winhi=sh
- If winhi>maxh Then winhi=maxh
- winx=maxw/2-winwid/2
- winy=maxh/2-winhi/2
-
- Free Window 0
- Window 0,winx,winy,winwid,winhi,$800|$1000,"",1,0
- BitMaptoWindow 1,0,0,0,0,0,winwid,winhi
-
- Free Palette 1
-
- Else ;We can't use the file - tell 'em why!
- Rq$=""
- If error$="MEM"
- Format "#,##0,000"
- Rq$="Not enough chip memory|Need:"+Str$(mem)+" bytes|Have:"+Str$(memchip)+" bytes"
- EndIf
- If error$="ERROR" Then Rq$="Unrecognized file type|"
- If Rq$=""
- Rq$="Can't process selected file|"
- If error$="NF"
- Rq$=Rq$+"File not found!"
- Else
- Rq$=Rq$+error$+" pictures not supported|"
- EndIf
- EndIf
- If error$<>"NF" AND error$<>"MEM" Then Rq$=Rq$+"Pictures must be IFF - ILBM"
- Request "Graphic load error",Rq$,"Cancel"
- EndIf
-
-
-
-
- ;------------Wait until the close gadget is pressed------------------------
- If error$="" ;if a picture was shown, wait for close gad
- WaitEvent
- Free Window 0
- ;Free BitMap 1
- success=FreeMem_(*b1p,b1size)
- EndIf
- Forever
-
-
-
-